
nums = [0,0,0], target = 1

var threeSumClosest = function(nums, target) {
    nums.sort((a,b)=>(a-b))
    let res=0
    let value=0
    let diff=Infinity
    for(let i=0;i<nums.length-2;i++)
    {
       let left=i+1
       let right=nums.length-1
       while(left<right)
       {
          res=nums[i]+nums[left]+nums[right]
          if(Math.abs(target-res)<diff)
          {
            diff=Math.abs(target-res)
            value=res
          }
          if(diff==0){
            return value
          }
          if(res<target){
            left++
          }
          else if(res>target){
            right--
          }
       }
    }
    return value





};
console.log(threeSumClosest(nums,target));
